#pragma once

#include <string>
#include <chrono>
#include <mutex>
#include "nlohmann/json.hpp"
#include "base_callback_list.h"

namespace El {
namespace Record {

class IndexWriter {
public:
    static IndexWriter &GetInstance();

    /**
     * @brief Add or update video entry in the index file
     * @param storePath Absolute storage path (must start with '/')
     * @param videoIndex Video index information
     * @return true if successful, false otherwise
     * @note The storePath must be an absolute path starting with '/'
     */
    bool WriteVideoIndex(const std::string &absolutePath, const nlohmann::json &videoIndex);

    /**
     * @brief Add or update image entry in the index file
     * @param storePath Absolute storage path (must start with '/')
     * @param imageIndex Image index information in JSON format
     * @return true if successful, false otherwise
     * @note The storePath must be an absolute path starting with '/'
     */
    bool WriteImageIndex(const std::string &absolutePath, const nlohmann::json &imageIndex);

private:
    IndexWriter() = default;
    ~IndexWriter() = default;

    /**
     * @brief 创建新的索引文件
     * @return 新创建的索引JSON对象
     */
    nlohmann::json CreateNewIndex();
};

} // namespace Record
} // namespace El